let token = localStorage.token

let holdBtn = document.querySelector('.holdBtn')
let userName = document.querySelector('.usnerName')
let userTel = document.querySelector('.userTel')
let userRegion = document.querySelector('.userRegion')
let userAddress = document.querySelector('.userAddress')
// 添加地址按钮
holdBtn.onclick =async function(){
    let username = localStorage.username;
    let realName = userName.value;
    let phoneNum = userTel.value;
    let region = userRegion.value
    let address = userAddress.value
    let userAdd = region+address
    let isDef = false
    try {let result = await axios({
        method: 'post',
        url: 'http://127.0.0.1:9527/api/user/addAdd',
        data: {
            username,
            realName,
            phoneNum,
            userAdd,
            isDef
        },
        headers: {
            'Authorization': 'Bearer ' + token
        }
    })
    let data = result.data;
    console.log(data);
    if (data.code === 1) {
        return alert(data.msg)
    } else {
        alert('添加成功')
        let timer = setTimeout(() =>{
            window.history.back()
            // location.href='../../html/YJJ/Address.html'
        })
    }} catch (error) {
        if (error.response.status == 401) {
            // 鉴权失败
            alert('用户未登录，请登录后进行访问')
            let timer = setTimeout(() => {
                window.history.back()
            })
        }
    }
}